// 支付sdk data 支付的参数 jumpAddress 跳转的地址
function pay(data, jumpAddress) {
  return new Promise((resolve, reject) =>{ 
    // 微信小程序的支付
    // #ifdef MP-WEIXIN
    wx.requestPayment({
      timeStamp: data.timeStamp,
      nonceStr: data.nonceStr,
      package: data.package,
      signType: data.signType,
      paySign: data.paySign,
      success: (result) => {
        uni.hideToast();
        if (result.errMsg == 'requestPayment:ok') {
          uni.showToast({
            title: '支付成功',
            icon: 'success'
          })
          if (jumpAddress) {
            uni.navigateTo({
              url: jumpAddress
            })
          }
          resolve();
        }
      },
      fail: (err) => {
        uni.hideToast();
        uni.showToast({
          title: '支付失败',
          icon: 'none'
        })
        if (jumpAddress) {
          uni.navigateTo({
            url: jumpAddress
          })
        }
        reject();
      }
    })
    // // #endif
  })
}

export default pay;